<?php

class Persona extends Maestra
{
	const COL_ID      		= 'ID_PERSONA';
	const COL_NOMBRE      	= 'NOMBRE_PERSONA';
	const COL_PATERNO      	= 'PATERNO_PERSONA';
	const COL_MATERNO      	= 'MATERNO_PERSONA';
	const COL_RUT      	= 'RUT_PERSONA';
	const COL_MAIL      	= 'EMAIL_PERSONA';
	const COL_FONO      	= 'FONO_PERSONA';
	const COL_PARTICULAR      	= 'PARTICULAR_PERSONA';
	const COL_DESPACHO      	= 'DESPACHO_PERSONA';
	const COL_LOGIN      	= 'LOGIN_PERSONA';
	const COL_PASS      	= 'PASS_PERSONA';
	const COL_ROL      	= 'ROL_PERSONA';
	const COL_FECHA      	= 'FECHA_REGISTRO';
	

	const TBL_NAME = 'persona';
	
	static public function getDatos($iID)
	{
		$oModel= self::getInstance();
		$sSql = "SELECT * FROM ".self::TBL_NAME;
		$sSql.= " WHERE ";
		$sSql.= self::COL_ID." = $iID";
		$arr = $oModel->dB->Execute($sSql);
		$oData = $arr->FetchObj();
		return $oData;
	}
	
	static public function getLoginCredential($l,$p)
	{
		$oModel= self::getInstance();
		$sSql = "SELECT * FROM ".self::TBL_NAME;
		$sSql.= " WHERE ";
		$sSql.= self::COL_LOGIN." like '$l' AND ".self::COL_PASS." like '$p'";
		$arr = $oModel->dB->Execute($sSql);
		$oData = $arr->FetchObj();
		return $oData;
	}	
		

	static public function getAll()
	{
		$oModel = self::getInstance();
		$sSql = "SELECT * FROM ".self::TBL_NAME;
		$arr = $oModel->dB->GetArray($sSql);
		return $arr;
	}	
	
	static public function insertar($aDatos)
	{
		$oCon = self::getInstance();
		if($oCon->dB->AutoExecute(self::TBL_NAME, $aDatos, 'INSERT'))
		{
			$lasId = $oCon->dB->Insert_ID();
		}else{
			$lasId = 0;
		}
		return $lasId;
	}

	static public function eliminar($aDatos, $id)
	{
		$oCon = self::getInstance();
		$iReturn = $oCon->dB->AutoExecute(self::TBL_NAME, $aDatos, 'UPDATE', self::COL_ID.'='.$id);
		return $iReturn;
	}

	static public function actualizar($aDatos, $id)
	{
		$oCon = self::getInstance();
		$iReturn = $oCon->dB->AutoExecute(self::TBL_NAME, $aDatos, 'UPDATE', self::COL_ID.'='.$id);
		return $iReturn;
	}
}

